<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>

<jsp:useBean id="nowDate" class="java.util.Date" />
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>管理编辑</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${ctx}/js/jsp/yd/logic/ItemStateData.js"></script>
<script type="text/javascript">
var basic_Url="${ctx}/yd/logic/so";
var ItemStateList = ItemStateData.Rows;//物料等级

var grid;
$(function(){
	//表格结构
	var griddata ={};
	grid = $("#table1").ligerGrid({
        columns: [{ display: 'ID', name: 'id', width: 1 , hide:true},
                  { display: '产品id', name: 'materialsid', width: 1 , hide:true},//使用selecturl时必须设置该属性
                  { display: '<font color="gray">产品编码</font>', name: 'prodNo',  width: 100},
				  { display: '<font color="gray">产品名称</font>', name: 'prodName', width: 100 },
				  { display: '<font color="gray">品牌型号</font>', name: 'prodModel', width: 1 , hide:true },
				  { display: '<font color="gray">型号规格</font>', name: 'prodSpecDesc', width: 160 },
				  { display: '<font color="gray">是否可用批次</font>', name: 'openBatch',hide:true, width: 160, render: function (item){
						if(item.openBatch=="Y"){
							return "可用";
						}else{
							return "不可用";
						}
				  }},
				  
				  { display: '<font color="gray">基本单位</font>', name: 'prodBUnit', width: 60},
				  { display: '<font color="gray">基本单位单价</font>', name: 'prodBUnitPrice', width: 80},
				  { display: '<font color="gray">单位换算率</font>', name: 'prodUnitConvert', width: 70},
				  { display: '<font color="gray">基本单位数量</font>', name: 'prodBQuantity', width: 80 , type: 'float'},
				  { display: '等级<font color="red">*</font>', name: 'status', width: 60
					  //<c:choose>
		           	    <c:when test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
						,editor: { type: 'select', data: ItemStateList, valueColumnName: 'ItemStateID', displayColumnName: 'ItemStateName'},
						 render: function (item){
				        for (var i = 0; i < ItemStateList.length; i++){
				        	if (ItemStateList[i]['ItemStateID'] == item.status){
				          	  	return ItemStateList[i]['ItemStateName'];
				            }
				        }
						return item.status;
						}
						</c:when>
						<c:otherwise>
						,render: function (item){
							 var state=item.status;
			           		  if(state=="1"){
			           			  return "一等品";
			           		  }
			           		  if(state=="2"){
			           			  return "次品";
			           		  }
			           		  if(state=="3"){
			           			  return "旧件";
			           		  }
							}
						</c:otherwise>
						</c:choose>
					},
				  { display: '当前单位<font color="red">*</font>', name: 'prodUnit', width: 80 
						//<c:if test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
						,editor : {
	           	 	   type:'selecturl',dataItem:'dataItem',path:'${ctx}/yd/basic/measurementUnit/unitlist.do',valueColumnName: 'unitname', displayColumnName: 'unitname'}, 
	           	 	   render: function (item){//渲染
	           	 		 	var dataitem = $.parseJSON($("#dataItem").val());
	           	 	   		var tmpProdUnit = item.prodUnit;
	           	 		  	if(undefined != dataitem){
	           	 			 	for (var i = 0; i < dataitem.length; i++){
	                                if (dataitem[i]['unitname'] == item.prodUnit&&dataitem[i]['materialscode']==item.prodNo){
	                                	//alert(dataitem[i]['unitconvert']);
	                                	item.prodUnitConvert = dataitem[i]['unitconvert'];
	                                	tmpProdUnit = dataitem[i]['unitname'];
	                                } 
	                            }
	           	 		  	}
	           	 			dealProductQuantity(item);
	                        return tmpProdUnit;
	                    }
	           	 	   //</c:if>
				  },
				  { display: '当前单位数量<font color="red">*</font>', name: 'prodQuantity', width: 100
					 //<c:if test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
					  ,editor: { type: 'float'},
					  render:function(item){
						  dealProductQuantity(item);
						  return item.prodQuantity;
					  }
					  //</c:if>
				  },
                  { display: '当前单位单价<font color="red">*</font>', name: 'prodPrice', width: 85
					 //<c:if test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
					  ,editor: { type: 'float'},
					  render:function(item){
						  if(($("#exchangeRate").val() != "" && $("#exchangeRate").val()!=null && $("#exchangeRate").val() != undefined) && (!isNaN(item.prodPrice) && item.prodPrice!=null && item.prodPrice != undefined)){
                			  item.prodRmbPrice=item.prodPrice*parseFloat($("#exchangeRate").val()).toFixed(4);
                		  }
						  dealProductPrice(item);
						  return (1*item.prodPrice).toFixed(4);
					  }
					//</c:if>
                  },
                  { display: '<font color="gray">人民币单价</font>', name: 'prodRmbPrice', width: 80,
                	  render:function(item){
                		 if(!isNaN(item.prodPrice) ){
                			  item.prodRmbPrice=(item.prodPrice*$("#exchangeRate").val()).toFixed(4);
                			  if(!isNaN(item.prodTaxRate)){
                    			  item.prodRmbPriceWithTax = (item.prodRmbPrice *(1+item.prodTaxRate*0.01)).toFixed(4);
                			  }
                		  }
                		  return item.prodRmbPrice;
                	  }
                  },
                  { display: '税率(%)<font color="red">*</font>', name: 'prodTaxRate', width: 80
                	//<c:if test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
                	  ,editor: { type: 'float'},
                	  render:function(item){
						  dealProductPrice(item);
						  var tmpShow = item.prodTaxRate;
						  if(undefined != item.prodTaxRate && null != item.prodTaxRate){
							  tmpShow +="";
						  }
						  return tmpShow;
					  }
                	//</c:if>
                  },
				  { display: '<font color="gray">基本单位含税单价</font>', name: 'prodBUnitPriceWithTax', width: 100},
				  { display: '<font color="gray">含税单价</font>', name: 'prodPriceWithTax', width: 110},
				  { display: '<font color="gray">含税人民币单价</font>', name: 'prodRmbPriceWithTax', width: 110},
                  { display: '<font color="gray">金额</font>', name: 'prodSum', width: 110},
                  //{ display: '折扣率(%)', name: 'prodDiscountRate', width: 150,editor: { type: 'float'}},
                  //{ display: '折扣额', name: 'prodDiscount', width: 150,editor: { type: 'float'}},
                  //{ display: '实际含税单价', name: 'prodActPriceWithTax', width: 150,editor: { type: 'float'}},
                  //{ display: '销项税额', name: 'prodXxTax', width: 150,editor: { type: 'float'}},
                  { display: '<font color="gray">价税合计</font>', name: 'prodTotal', width: 110},
                  //{ display: '币种', name: 'currency', width: 150,editor: { type: 'float'}},
                  //{ display: '汇率', name: 'exchangeRate', width: 150,editor: { type: 'float'}},
                  //{ display: '交货日期', name: 'deliveryDate', width: 150,editor: { type: 'float'}},
                  { display: '出库基本单位数量', name: 'ckBQuantity', width: 1,type:'float',hide:true},
                  { display: '<font color="gray">出库数量</font>', name: 'ckQuantity', width: 80,type:'float'},
                  { display: '已退基本单位数量', name: 'ytBQuantity', width: 1,type:'float',hide:true},
                  { display: '<font color="gray">已退数量</font>', name: 'ytQuantity', width: 80,type:'float'},
                  { display: '冻结基本单位数量', name: 'frozenBQuantity', width: 1,type:'float',hide:true},
                  { display: '<font color="gray">冻结数量</font>', name: 'frozenQuantity', width: 80,type:'float'},
                  { display: '冻结已出库基本单位数量', name: 'frozenCkBQty', width: 1,type:'float',hide:true},
                  { display: '<font color="gray">冻结已出库数量</font>', name: 'frozenCkQty', width: 120,type:'float'},
                  //{ display: '基本单位开票数量', name: 'kpBQuantity', width: 150,editor: { type: 'float'}},
                  //{ display: '开票数量', name: 'kpQuantity', width: 150,editor: { type: 'float'}},
                  //{ display: '组装数量', name: 'zzBQuantity', width: 150,editor: { type: 'float'}},
                  { display: '备注', name: 'remark', width: 150
                		//<c:if test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
                  		,editor: { type: 'text'}
                    	//</c:if>
                  }
                  ],
                  enabledEdit: true,
                  usePager: true,pageSize:1000,pageSizeOptions:[1000],
                  //data : griddata,
                  parms:[{ name : 'id' , value : '${so.id}'}],
                  url : basic_Url+"/griditems.do",
                  
                  width: "100%", height:'90%', checkbox: true
                //<c:if test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
                  ,toolbar: { items: [
                                     { text: '添加物料', click: ItemWindow, icon: 'add' },
                                     { line: true },
                                     { text: '删除', click: deleteRow, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
                                     ]
                           }
                //</c:if>
     });
	
	//表格数据加载

	/* var manager = $("#table1").ligerGetGridManager();
	//<c:forEach items='${soitem}' var='item'>
    	manager.addRow2({
    		id : "${item.id}" ,
    		materialsid:"${item.materialsid}",
    		prodNo :"${item.prodNo}",
    		prodName: "${item.prodName}",
    		prodModel :"${item.prodModel}",
    		prodSpecDesc :"${item.prodSpecDesc}",
    		prodBUnit :"${item.prodBUnit}",
    		prodBQuantity :"${item.prodBQuantity}",
    		prodUnit :"${item.prodUnit}",
    		prodUnitConvert:"${item.prodUnitConvert}",
    		prodQuantity :"${item.prodQuantity}",
    		prodBUnitPrice :"${item.prodBUnitPrice}",
    		prodBUnitPriceWithTax :"${item.prodBUnitPriceWithTax}",
    		prodPrice :"${item.prodPrice}",
    		prodPriceWithTax :"${item.prodPriceWithTax}",
    		prodSum :"${item.prodSum}",
    		prodTaxRate :"${item.prodTaxRate}",
    		status :"${item.status}",
//     		prodDiscountRate :"${item.prodDiscountRate}",
//     		prodDiscount :"${item.prodDiscount}",
//     		prodActPriceWithTax :"${item.prodActPriceWithTax}",
//     		prodXxTax :"${item.prodXxTax}",
    		prodTotal :"${item.prodTotal}",
    		ckBQuantity :"${item.ckBQuantity}",
    		ckQuantity :"${item.ckQuantity}",
    		ytBQuantity :"${item.ytBQuantity}",
    		ytQuantity :"${item.ytQuantity}",
    		frozenBQuantity :"${item.frozenBQuantity}",
    		frozenQuantity :"${item.frozenQuantity}",
    		frozenCkBQty:"${item.frozenCkBQty}",
			frozenCkQty:"${item.frozenCkQty}",
    		kpBQuantity :"${item.kpBQuantity}",
    		kpQuantity :"${item.kpQuantity}",
    		openBatch :"${item.openBatch}",
    		remark :"${item.remark}"
        });
    //</c:forEach> */
//修正行数
//     manager.options.total = manager.getData.length;
//     manager.reRender();//_buildPager();reRender();
    
	
	//表单提交触发
	$("#inputForm").validate({			   
	onsubmit: true,
	 /*执行ajaxsubmit  */ 
    submitHandler: function(editform) {
        try{			    		
            url =  basic_Url+"/save.do";
            var api = frameElement.api;
        	var W = api.opener;
            getReturnMessage(url,"inputForm",W.searchAP);
        }catch(e){alert(e);}
    }
	});
	
	//按钮处理
	/* btn status */
	$("[id^='btn_fb_']").hide();
	var curStatus = "${so.billstatus}";//当前所在环节、状态
	//var curwareStatus
	if(curStatus == ''){//建单
		$("#btn_fb_save").show();
	}else {
		$("#btn_fb_exportExcel").show();
		formComponentDisabled(true);//禁用控件
		if (curStatus == '0'||curStatus == '6' ||curStatus == '7'){//草稿状态-提交二级
			if("${user.name}"=="${so.dcruser}"){
				$("#btn_fb_approve_2").show();
				$("#btn_fb_cancel").show();
			}
			formComponentDisabled(false);//启用控件
		}else if (curStatus == '2'){//二级审批中状态
			$("#btn_fb_approve_3").show();
			$("#btn_fb_rebut_2").show();
			$("#btn_fb_end_2").show();
		}else if (curStatus == '3'){//三级审批中状态
			$("#btn_fb_rebut_3").show();
			$("#btn_fb_end_3").show();
		}else if (curStatus == '4'){//二级结案状态
			//冻结、出库被操作后不可驳回
			if('0'=="${so.frozenStatus}" && '0'=="${so.wareStatus}"){
				$("#btn_fb_rebut_3").show();
			}
			showForceFinishBtn();
		}else if (curStatus == '5'){//三级结案状态
			showForceFinishBtn();
		}else{
			
		}
		
	}
	
	/**
	 * 如果是拟稿人，并且未完全出库，则显示强制完结按钮
	 */
	function showForceFinishBtn(){
		if(("${user.name}"=="admin" || "${user.name}"=="${so.dcruser}") && ('0'=="${so.wareStatus}" || '1'=="${so.wareStatus}")){
			$("#btn_fb_force_finish").show();
		}
	}
	
	//页面加载标识隐藏
	$("#pageloading").hide();
	
	//=============================

	
	//添加模式隐藏DIV
	if("${flag}" =="ADD"){
		$("#tr1").hide();
		//$("#tr2").hide();
	}
	
	//客户编码改变触发
	$("#cliNo").change(function() {//TODO完善
		$("#cliName").val("");
		$("#cliAddr").val("");
		$("#cliPeo").val("");
		$("#cliTel").val("");
		$("#cliFax").val("");
		if(''!= $(this).val()){
			$.ajax({
    		      url: basic_Url+"/getClientBeanByNo.do",
    		      global: false,
    		      type: "POST",
    		      dataType: "json",
    		      data: ({
    		    	  cliNo : $(this).val()
    		      }),		     
    		      success: function(o){
    		    	if(undefined != o && undefined != o.bean && null != o.bean){
    		    		$("#cliName").val(o.bean.name);
    		    		$("#cliAddr").val(o.bean.address);
    		    		$("#cliPeo").val(o.bean.attachperson);
    		    		$("#cliTel").val(o.bean.telephone);
    		    		$("#cliFax").val(o.bean.fax);
    		    	}else{
    		    		alert("返回对象为空");
    		    	}
    	   			
    		      }
    	   });
		}
	});

    //币种改变触发- 
    var tmpOldCurrency = "";
	$("#currency").change(function() {//TODO完善
		
		var data = grid.getData();
		if(null != data && data.length > 0){
			//清空表格
			$.ligerDialog.confirm("改变币种后产品表格将清空，是否确认更改币种?", 
				function (flag) { 
				if(flag){
					grid.loadData({});//清空表格
					tmpOldCurrency = $("#currency").val();//恢复币种
					currencyChangeExchangeRate();
				}else{
					$("#currency").val(tmpOldCurrency);//赋值币种
				}
			}); 
// 			$(data).each(function (){
// 				if(!isNaN(this.prodPrice) ){
//        			  this.prodRmbPrice=(this.prodPrice*$("#exchangeRate").val()).toFixed(4);
//        		  	}
// 			});
// 			grid.reRender();
		}else{
			currencyChangeExchangeRate();
		}
	});
	
	/**
	 * 币种触发汇率
	 */
	function currencyChangeExchangeRate(){
		if(''== $("#currency").val()){
			$("#exchangeRate").val('');
		}
		//<c:forEach items='${currency}' var='item'>
		else if ('${item.currencyname}' == $("#currency").val()) {
			$("#exchangeRate").val('${item.exchangeRate}');
			tmpOldCurrency = $("#currency").val();
			
		}
		//</c:forEach>
	}
    
});

	//物料列表
	function ItemWindow() {
		var exchangeRate = $("#exchangeRate").val();
		if(""==exchangeRate ||isNaN(exchangeRate)){
			$.dialog.alert("请先选择币别");
			return ;
		}
		getDG().dialog(
				{
					title : '选择产品',
					width : 650,
					height : 350,
					content : 'url:' + sys_context
						//	+ '/public/windowalert/itemmanager.do?typeName='+encodeURIComponent("成品物料"), //只查询成品
							+ '/public/windowalert/itemmanager.do',    //查询所有物料，不区分成品和原材料  
					lock : true,
					max : true,
					min : true,
					ok : function() {
						var getSelectedHub = this.content.getSelected();
						var manager = $("#table1").ligerGetGridManager();
						//alert(JSON.stringify(getSelectedHub));
						if (getSelectedHub != null) {
							$(getSelectedHub).each(function() {
								manager.addRow2({
									prodName : this.name,
									//prodModel : this.brand,
									prodPrice : this.price/parseFloat(exchangeRate).toFixed(4),// TODO 报价带出
									prodSpecDesc : this.spec,
									prodBUnit : this.unit,
									materialsid: this.id,//物料ID
									openBatch : this.remark2,
									ckBQuantity:0,
									ckQuantity:0,
									ytBQuantity:0,
									ytQuantity:0,
									frozenBQuantity:0,
									frozenQuantity:0,
									frozenCkBQty:0,
									frozenCkQty:0,
									prodNo : this.code
								});
							});
						}
						this.content.Close();
						return false;
					},
					cancelVal : '关闭',
					cancel : true
				}).zindex();
	}
	

	//表单提交触发
	function submitForm(param) {
		//设置ajax全局同步
		$("#paramflag").val(param);

		var data = grid.getData();
		var dl = grid.getDeleted();
		if (data.length == 0) {
			$.dialog.alert("请选择申请产品");
			return false;
		}
		
		var ba = true;
		if (data != null) {
			var j = 0;
			if (param == 0 || param == 1){//指向状态
				
				$(data).each(function() {
						j++;
						
						if (undefined == this.status
								|| null == this.status) {
							$.dialog.alert("第" + j + "行的“等级”数据不合法");
							ba = false;
							return false;
						}
						
						if (undefined == this.prodPrice
								|| isNaN(this.prodPrice)
								|| this.prodPrice <= 0) {
							$.dialog.alert("第" + j + "行的“单价”数据不合法");
							ba = false;
							return false;
						}
						
						if (undefined == this.prodQuantity
								|| isNaN(this.prodQuantity)
								|| this.prodQuantity <= 0) {
							$.dialog.alert("第" + j + "行的“数量”数据不合法");
							ba = false;
							return false;
						}
						
						if (undefined == this.prodUnit
								|| ""==this.prodUnit) {
							$.dialog.alert("第" + j + "行的“单位”数据不合法");
							ba = false;
							return false;
						}
						
						if (undefined == this.prodTaxRate
								|| isNaN(this.prodTaxRate)
								|| this.prodTaxRate < 0) {
							$.dialog.alert("第" + j + "行的“税率”数据不合法");
							ba = false;
							return false;
						}
						
						if (undefined == this.prodPriceWithTax
								|| isNaN(this.prodPriceWithTax)
								|| this.prodPriceWithTax <= 0) {
							$.dialog.alert("第" + j + "行的“含税单价”数据不合法");
							ba = false;
							return false;
						}
				});
			 }
		}
		
		
		
		jQuery.ajaxSettings.async = false;
		if (ba) {
			//
			
			$("#itemdata").val(JSON.stringify(data));
			$("#itemdelete").val(JSON.stringify(dl));
			$("#submitFlag").val(param);
			formComponentDisabled(false);//启用控件
			$("#inputForm").submit();
		}
	}
	
	function tableSubmit(msg,param){
		$.ligerDialog.confirm(msg, 
				function (flag) { 
				if(flag){
					submitForm(param);
					}
			}); 
	}
	
	function submitFormClose(param){
		tableSubmit('是否确认关闭单据操作？',param);
	}
	
	function submitFormEnd(param){
		tableSubmit('是否确认审批完结操作？',param);
	}
	
	function submitFormRebut(param){
		tableSubmit('是否确认驳回操作？',param);
	}
	

	function deleteRow() {
		grid.deleteSelectedRow();
	}

	/**
	 * 导出
	 */
	function exportExcel() {
		var path = basic_Url + "/exportExcel.do?id=${so.id}";
		window.open(path, "_blank");
	}
	
    /**
     * 产品的数量计算
     * @param item
     */
    function dealProductQuantity(item){
    	if(undefined == item){
    		return;
    	}
    	
    	//计算
    	//计算基本单位数量 parseFloat()
    	if(!isNaN(item.prodQuantity) && !isNaN(item.prodQuantity)){
    		item.prodBQuantity = item.prodQuantity*item.prodUnitConvert ;
    	}else{
    		item.prodBQuantity=null;//清除值
    	}
    	
    	//联动价格计算
    	dealProductPrice(item);
    }
    
    /**
     * 产品的价格计算
     * @param item
     */
    function dealProductPrice(item){
    	if(undefined == item){
    		return;
    	}
    	
    	//清空数据
    	item.prodPriceWithTax=null;
    	item.prodSum=null;
    	item.prodTotal=null;
    	item.prodRmbPriceWithTax=null;
    	item.prodBUnitPrice=null;
    	item.prodBUnitPriceWithTax=null;
    	
    	//价格计算
    	if(!isNaN(item.prodPrice)){
    		//RMB单价 - add 20130905
//     		if(!isNaN($("#exchangeRate").val())){
//     			item.prodRmbPrice=(item.prodPrice*$("#exchangeRate").val()).toFixed(4);
//     		}
    		if(!isNaN(item.prodTaxRate)){
    			//含税单价
    			item.prodPriceWithTax = item.prodPrice * (1 + item.prodTaxRate*0.01);
    			item.prodPriceWithTax = item.prodPriceWithTax.toFixed(4);//解决浮点数精度问题
    			//人民币含税单价
    			item.prodRmbPriceWithTax = item.prodRmbPrice * (1 + item.prodTaxRate*0.01);
    			item.prodRmbPriceWithTax = item.prodRmbPriceWithTax.toFixed(4);
    		}
        	if(!isNaN(item.prodUnitConvert)){
        		item.prodBUnitPrice = item.prodPrice/item.prodUnitConvert;
        		item.prodBUnitPrice = item.prodBUnitPrice.toFixed(4);
    			if(!isNaN(item.prodPriceWithTax)&&item.prodPriceWithTax!=null){
    				//含税合计
        			item.prodBUnitPriceWithTax = item.prodBUnitPrice *  (1 + item.prodTaxRate*0.01);
        			item.prodBUnitPriceWithTax = item.prodBUnitPriceWithTax.toFixed(4);
        		}
        	}
    		
    		if(!isNaN(item.prodQuantity)){
    			//金额
    			item.prodSum = item.prodQuantity * item.prodPrice;
    			item.prodSum  = item.prodSum.toFixed(4);//解决浮点数精度问题
    			
    			if(!isNaN(item.prodPriceWithTax)){
    				//含税合计
        			item.prodTotal = (item.prodQuantity * item.prodPriceWithTax).toFixed(4);
        		}
    		}
    	}
    }
</script>

</head>

<body>

<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${so.id}"/>
<input type="hidden" id="version" name="version" value="${so.version}"/>
<input type="hidden" id="itemdata" name="itemdata" value=""/>
<input type="hidden" id="dataItem" name="dataItem"/><!-- 单位获取辅助 -->
<input type="hidden" id="itemdelete" name="itemdelete" value=""/>
<input type="hidden" id="paramflag" name="paramflag" value=""/>
<!-- 用于标识提交按钮 -->
<input type="hidden" id="submitFlag" value="" />
 <div class="pageContent" >
    <div class="panel">
         <table class="TableBlock" align="center">
         			<tr id="tr1">
   		           		<td nowrap="nowrap" width="20%">销售订单编号:</td>
   		                <td width="30%">
   		                	<input class="inp_width_98p" type="text" id="no" name="no" value="${so.no}"  readonly="readonly"/>
   		                </td>
   		                <td nowrap="nowrap" width="20%">建单时间:</td>
						<td width="30%"><input class="inp_width_98p" type="text" id="dctime" name="dctime"
							value="<fmt:formatDate value="${empty so.dctime?nowDate:so.dctime}" type="both" dateStyle="long" pattern="yyyy-MM-dd" />" readonly="readonly"/></td>
   		           </tr>
                   <tr>
                    	<td nowrap="nowrap" width="20%">客户订单号:</td>
   		                 <td width="30%">
   		                	<input type="text" id="cliOrderNo" name="cliOrderNo" value="${so.cliOrderNo}" class="inp_width_98p required"/>
   		                 </td>
   		                 <td nowrap="nowrap" width="20%">客户编号:</td>
   		           		<td width="30%">
   		           		<c:choose>
   		           		<c:when test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
   		           		<select id="cliNo" name="cliNo" class="inp_width_98p required" >
   		                 	<option></option>
   		                 	<c:forEach items="${bcList }" var="item">
   		                 		<option value="${item.code }">${item.code } - ${item.name } </option>
   		                 	</c:forEach>
   		                 </select>
   		                 	<script type="text/javascript">
   		           				$("#cliNo").val("${so.cliNo}");
   		           			</script>
   		           		</c:when>
						<c:otherwise>
						<input type="text" value="${so.cliNo}" id="cliNo" name="cliNo" class="inp_width_98p required" readonly="readonly"></input>
						</c:otherwise>
						</c:choose>
   		           		</td>
   		           </tr>
   		           <tr>
<!--    		           		<td nowrap="nowrap">选单号:</td> -->
<%--    		           		<td><input type="text" id="sourceBliiNo" name="sourceBliiNo" value="${so.sourceBliiNo}"></input></td> --%>
   		           		<td nowrap="nowrap">客户单位名称:</td>
   		           		<td><input type="text" id="cliName" name="cliName" value="${so.cliName}" class="inp_width_98p required" readonly="readonly"></input></td>
   		           		<td nowrap="nowrap">客户联系人:</td>
   		           		<td><input type="text" id="cliPeo" name="cliPeo" value="${so.cliPeo}" class="inp_width_98p required"></input></td>
   		           		
   		           </tr>
   		           <tr>
   		           		<td nowrap="nowrap">客户联系电话:</td>
   		           		<td><input type="text" id="cliTel" name="cliTel" value="${so.cliTel}" class="inp_width_98p required"></input></td>
   		           		<td nowrap="nowrap">传真:</td>
   		           		<td><input type="text" id="cliFax" name="cliFax" value="${so.cliFax}" class="inp_width_98p"></input></td>
   		           </tr>
   		           <tr>
   		           		<td nowrap="nowrap">交货时间:</td>
   		           		<td><input type="text" id="deliveryDate" name="deliveryDate" class="inp_width_98p Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate" value="<fmt:formatDate value="${so.deliveryDate}" pattern="yyyy-MM-dd" type="both" />"  readonly="readonly"></input></td>
   		           		<td nowrap="nowrap">收款时间:</td>
   		           		<td><input type="text" id="receipDate" name="receipDate" class="inp_width_98p Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate" value="<fmt:formatDate value="${so.receipDate}" pattern="yyyy-MM-dd" type="both" />"  readonly="readonly"></input></td>
   		           </tr>
   		           <tr>
   		           		<td nowrap="nowrap">客户地址:</td>
   		            	<td colspan="3">
   		                	<input type="text" id="cliAddr" name="cliAddr" value="${so.cliAddr}" class="inp_width_98p" />
   		             	</td>
   		           </tr>
   		           <tr>
   		           		<td nowrap="nowrap">付款方式:</td>
   		           		<td>
   		           		<c:choose>
   		           		<c:when test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
   		           		<select id="payMode" name="payMode" class="inp_width_98p required" >
   		                 	<option></option>
   		                 	<c:forEach items="${payments }" var="item">
   		                 		<option value="${item.name }">${item.name }</option>
   		                 	</c:forEach>
   		                 </select>
   		                 	<script type="text/javascript">
   		           				$("#payMode").val("${so.payMode}");
   		           			</script>
   		           		</c:when>
						<c:otherwise>
						<input type="text" value="${so.payMode}" id="payMode" name="payMode" class="inp_width_98p required" readonly="readonly"></input>
						</c:otherwise>
						</c:choose>
   		           		</td>
   		           		<td nowrap="nowrap">交货方式:</td>
   		           		<td>
   		           		<c:choose>
   		           		<c:when test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
   		           		<select id="deliveryMode" name="deliveryMode" class="inp_width_98p required" >
   		                 	<option></option>
   		                 	<c:forEach items="${deliveries }" var="item">
   		                 		<option value="${item.name }">${item.name }</option>
   		                 	</c:forEach>
   		                 </select>
   		                 	<script type="text/javascript">
   		           				$("#deliveryMode").val("${so.deliveryMode}");
   		           			</script>
   		           		</c:when>
						<c:otherwise>
						<input type="text" value="${so.deliveryMode}" id="deliveryMode" name="deliveryMode" class="inp_width_98p required" readonly="readonly"></input>
						</c:otherwise>
						</c:choose>
   		           		</td>
   		           </tr>
   		           <tr>
   		           		<td nowrap="nowrap">币别:</td>
   		           		<td>
   		           		<c:choose>
   		           		<c:when test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
   		           		<select id="currency" name="currency" class="inp_width_98p required">
								<option></option>
								<c:forEach items="${currency }" var="item">
									<option value="${item.currencyname }">${item.currencyname}</option>
								</c:forEach>
						</select> 
						<script type="text/javascript">
							$("#currency").val('${so.currency}');
						</script>
						</c:when>
						<c:otherwise>
						<input type="text" value="${so.currency}" id="currency" name="currency" class="inp_width_98p required" readonly="readonly"></input>
						</c:otherwise>
						</c:choose>
						</td>
   		           		<td nowrap="nowrap">汇率:</td>
   		           		<td><input type="text" id="exchangeRate" name="exchangeRate" value="${so.exchangeRate}" class="inp_width_98p required" readonly="readonly"></input></td>
   		           </tr>
   		           <%-- <tr>
   		           		<td nowrap="nowrap">交货地址:</td>
   		            	<td colspan="3">
   		                	<input style="width: 98%;" type="text" id="deliveryAddr" name="deliveryAddr" value="${so.deliveryAddr}" />
   		             	</td>
   		           </tr> --%>
   		           <tr>
   		           		<td nowrap="nowrap">结算方式:</td>
   		           		<td><input type="text" id="balanceMode" name="balanceMode" value="${so.balanceMode}" class="inp_width_98p required"></input></td>
   		           		<td nowrap="nowrap">结算时间:</td>
   		           		<td><input type="text" id="balanceDate" name="balanceDate" class="inp_width_98p Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="<fmt:formatDate value="${so.balanceDate}" pattern="yyyy-MM-dd" type="both" />"  readonly="readonly"></input></td>
   		           </tr>
   		           <tr>
   		           		<td nowrap="nowrap">制单人:</td>
   		           		<td><input type="text" id="listerName" name="listerName" value="${empty so.listerName?user.realName:so.listerName}" class="inp_width_98p" readonly="readonly"></input></td>
   		           		<td nowrap="nowrap">制单人部门:</td>
   		           		<td>
   		           		<c:choose>
   		           		<c:when test="${'ADD' eq flag or '0'eq so.billstatus or '6'eq so.billstatus or '7'eq so.billstatus}">
   		           		<select id="listerDeptName" name="listerDeptName" class="inp_width_98p">
								<option></option>
								<c:forEach items="${depts }" var="item">
									<option value="${item.depname }">${item.depname}</option>
								</c:forEach>
						</select> 
   		           			<script type="text/javascript">
   		           				$("#listerDeptName").val("${so.listerDeptName}");
   		           		</script>
   		           		</c:when>
						<c:otherwise>
						<input type="text" value="${so.listerDeptName}" id="listerDeptName" name="listerDeptName" class="inp_width_98p" readonly="readonly"></input>
						</c:otherwise>
						</c:choose>
   		           		</td>
   		           </tr>
   		           <%-- <tr id="tr2">
   		           		<td nowrap="nowrap">审核人:</td>
   		           		<td><input type="text" id="auditorName" name="auditorName" value="${so.auditorName}" readonly="readonly"></input></td>
   		           		<td nowrap="nowrap">批准人:</td>
   		           		<td><input type="text" id="approverName" name="approverName" value="${so.approverName}" readonly="readonly"></input></td>
   		           </tr> --%>
   		           <tr>
                    <td nowrap="nowrap">备注:</td>
   		                 <td colspan="3">
   		                <input class="inp_width_98p" type="text" id="remark" name="remark" value="${so.remark}" />
   		                 </td>
   		           </tr>
                </table>
                <div id="table1"> </div>               
         </div>
         <div class="formBar">
	        <ul>
		        <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="btn_fb_save" onclick="submitForm(0)">保存</button></div></div></li>
		        <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="btn_fb_approve_2" onclick="submitForm(2)" title="提交二级审核">提交</button></div></div></li>
		        <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="btn_fb_force_finish" onclick="submitForm(-1)" title="订单强制完结出库">完结出库</button></div></div></li>
		      	<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="btn_fb_cancel" onclick="submitForm(8)" title="关闭订单">取消</button></div></div></li>
		      	
		      	<webres:displaycontroller elementId="LOGIC_SO_2SEHNHE" description="销售订单二级审核">
		      	<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="btn_fb_approve_3" onclick="submitForm(3)" title="提交三级审核">二级审核</button></div></div></li>
		      	</webres:displaycontroller>
		      	<webres:displaycontroller elementId="LOGIC_SO_2WANJIE" description="销售订单二级完结">
		      	<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="btn_fb_end_2" onclick="submitFormEnd(4)" title="二级结案">二审完结</button></div></div></li>
		      	</webres:displaycontroller>
		      	<webres:displaycontroller elementId="LOGIC_SO_3WANJIE" description="销售订单三级完结">
		      	<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="btn_fb_end_3" onclick="submitFormEnd(5)" title="三级结案">三审完结</button></div></div></li>
		      	</webres:displaycontroller>
		      	
		      	<webres:displaycontroller elementId="LOGIC_SO_2BOHUI" description="销售订单二级驳回">
		      	<li><div class="button"><div class="buttonContent"><button type="button" id="btn_fb_rebut_2" onclick="submitFormRebut(6)" title="二级驳回到草稿">驳回</button></div></div></li>
		      	</webres:displaycontroller>
		      	<webres:displaycontroller elementId="LOGIC_SO_3BOHUI" description="销售订单三级驳回">
		      	<li><div class="button"><div class="buttonContent"><button type="button" id="btn_fb_rebut_3" onclick="submitFormRebut(7)" title="三级驳回到草稿">驳回</button></div></div></li>
		      	</webres:displaycontroller>
		      	
		      	<li><div class="button"><div class="buttonContent"><button type="button" id="btn_fb_exportExcel" class="export" onclick="exportExcel()">导出</button></div></div> </li>
		       <li><div class="button"><div class="buttonContent"><button type="button" onclick="CloseDialog()">关闭</button></div></div></li>
	        </ul>
        </div>    
    </div>
</form>
</body>
</html>
